/**************************************************************************************
 *  Copyright (c)  2010  Leszek Karcz, Changmin Bae
 *  Permission is granted to copy, distribute and/or modify this document
 *  under the terms of the GNU Free Documentation License, Version 1.3
 *  or any later version published by the Free Software Foundation;
 *  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 *  A copy of the license is included in the section entitled "GNU
 *  Free Documentation License". 
 **************************************************************************************/
package data.tileables;
import data.Map;
import data.Player;
import data.missions.MoveToRally;
import data.missions.PowerDown;
import data.missions.PowerUp;

/**************************************************************************************
 * Author(s): Leszek Karcz, Changmin Bae
 * ColonyShip unit, turns into base
 **************************************************************************************/
public class ColonyShip extends Unit
{
	public static final int [] PRICE = { 0, 0, 0 };
	public static final int BUILDTIME = 10;
	private int workers;
	/**************************************************************************************
	 * Author(s): Leszek Karcz, Changmin Bae
	 * ColonyShip constructor
	 **************************************************************************************/
	public ColonyShip(int ID, int supertypeID, Player player, int workers)
	{
		super(ID, supertypeID, player);
		this.setType("Colony Ship");
		this.workers=workers;
		this.setImage("unit_colonyship");
		this.setIcon("unit_colonyship");
		this.setStats(10, 10, 5, 1, 1, 1);
		this.setUpkeep(new int[]{1,1,1});
		this.setDisplayLevel(3);
		this.setNumberOfCommands(4);
	}
	
	
	/**************************************************************************************
	 * Author(s): Leszek Karcz
	 * get icon file  name, highlight file name
	 **************************************************************************************/
	public String[] getImageData(int playerID)
	{
		return new String[]{((this.getPlayerID()==playerID) && (this.equals(this.player.getSelected())) ? "pselected_struct_h" : "p"+this.getPlayerID()+"_struct_h"),"unit_colonyship_0",""+this.getHealthPercentage()};
	}
	
	/**************************************************************************************
	 * Author(s): Leszek Karcz, Changmin Bae
	 * returns list of possible commands
	 **************************************************************************************/
	public String[] getCommandsText()
	{
		return new String[]{"Go to rally #", "Decommision" ,((this.getState()==0)? "Power up" : "Power Down") ,"Deploy"};
	}

	/**************************************************************************************
	 * Author(s): Changmin Bae
	 * remove ColonyShip from game
	 **************************************************************************************/
	public void die()
	{ 
		super.die();
		player.removeColonyShip(this);
	}

	/**************************************************************************************
	 * Author(s): Changmin Bae
	 * execute selected commands
	 * 0 - Go to rally #
	 * 1 - Decommission
	 * 2 - Power Up / Power down
	 * 3 - Deploy
	 **************************************************************************************/
	public boolean enqueueSelectedCommand(String mode, Map m, int x, int y) 
	{
		this.clearMissions();
		switch(this.getSelectedCommand())
		{
		case 0:
			try  
			{  
				this.addMission(new MoveToRally(this, m, player, Integer.parseInt(mode)));
			}
			catch(Exception e){}
			break;
		case 1:
			this.die();
			break;
		case 2:
			if(this.getState() == 0)
				this.addMission(new PowerUp(this));
			else
				this.addMission(new PowerDown(this));
			break;
		case 3:
			System.out.println("triggered case 3"); //changmin
			if(player.createBase(this.getX(), this.getY(), this.workers))
			{
				die();
				
			}
		}		
		return true;
	}
}
